package com.clkj.nangang.mvp;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.view.MenuItem;

import com.clkj.nangang.R;
import com.clkj.nangang.mvp.adapter.ViewPagerAdapter;
import com.clkj.nangang.mvp.base.BaseActivity;
import com.clkj.nangang.mvp.index.FragmentIndex;
import com.clkj.nangang.mvp.personcenter.FragmentPerson;
import com.clkj.nangang.util.BottomNavigationViewHelper;
import com.clkj.nangang.widget.NoScrollViewPager;

public class MainActivity extends BaseActivity {


    private BottomNavigationView navigation;
    private NoScrollViewPager vpMain;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initData();
        initView();
        assignView();
    }

    public void initData() {

    }

    @Override
    public void assignView() {

        //BottomNavigationView的选择事件
        navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                switch (item.getItemId()) {
                    case R.id.navigation_index:
                        vpMain.setCurrentItem(0);
                        return true;
                    case R.id.navigation_person_work:
                        vpMain.setCurrentItem(1);
                        return true;
                }
                return false;
            }
        });
    }

    public void initView() {
        navigation = (BottomNavigationView) findViewById(R.id.navigation);
        vpMain = (NoScrollViewPager) findViewById(R.id.vp_main);
        BottomNavigationViewHelper.disableShiftMode(navigation);//去掉动画效果

        setupViewPager(vpMain);
    }

    private void setupViewPager(NoScrollViewPager vpMain) {
        ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());

        adapter.addFragment(FragmentIndex.newInstance(""));
        adapter.addFragment(FragmentPerson.newInstance(""));
        vpMain.setAdapter(adapter);

        vpMain.setOffscreenPageLimit(2);
        vpMain.setCurrentItem(0);
    }

}
